package test;

/*
 *
 * FileOutputDemo
 *
 * Demonstration of FileOutputStream and
 * PrintStream classes
 *
 */

import java.io.*;

class FileOutputDemo 
{	
	public static void main(String args[])
	{
		FileOutputStream fileoutstream; // declare a file output object
		PrintStream printstream; // declare a print stream object

		try
		{
			// check if file exists
			File file = new File("myfile.txt");
			System.out.println(file + (file.exists()? " is found " : " is missing "));
			
			// Create a new file output stream
			// connected to "myfile.txt"
			fileoutstream = new FileOutputStream("myfile.txt");
			
			// Connect print stream to the output stream
			printstream = new PrintStream( fileoutstream );
			
			printstream.println ("This is written to a file");
	
			printstream.close();
		}
		catch (Exception e)
		{
			System.err.println ("Error writing to file");
		}
	}
}